<template>
    <view class="bh-row bh-justify-space-between container">
        <view>{{ label }}</view>
        <view class="">{{  }}</view>
    </view>
</template>
<script>
import { Api } from '../../api/api'

export default {
    emits: ['change'],
    props: {
        label: {
            type: String,
            default: ''
        },
        placeholder: {
            type: String,
            default: ''
        },
        value: {
            type: String,
            default: ''
        }
    },
    data(){
        return {
            rangeData: [[{name:''}],[{name:''}]],
            rangeValue: [0,0],
            streetAreaList: []
        }
    },
    methods: {
        columnChange(e){
            console.log('改变某一列的值', e)
            let that = this
            let column = e.detail.column
            let value = e.detail.value
            if(column == 0){
                that.rangeValue[0] = value
                that.rangeData[1] = that.rangeData[0][value].subList
            }
        },
        confirm(e){
            let that = this
            console.log('街道选择改变', e)
            that.rangeValue = e.detail.value
            that.$emit('change', {
                areaCode: that.streetAreaList[that.rangeValue[0]].code,
                areaName: that.streetAreaList[that.rangeValue[0]].name,
                street: that.streetAreaList[that.rangeValue[0]].subList[that.rangeValue[1]].name,
            })
        },
    },

    mounted(){
        let that = this
        Api.ConstantApi.areaStreetList(that.$store.state.currentRegion.cityCode, (res) => {
            if(res.code = 200){
                that.streetAreaList = res.data
                that.rangeData = [res.data, res.data[0].subList]
                if(that.selectedRegion.areaCode){
                    for(var i=0;i<res.data.length;i++){
                        if(res.data[i].code == that.selectedRegion.areaCode){
                            that.rangeData[0] = res.data[i]
                            that.rangeValue[0] = i
                            for(var j=0;j<res.data[i].subList.length;j++){
                                if(res.data[i].subList[j].name == that.selectedRegion.street){
                                    that.rangeData[1] = res.data[i].subList
                                    that.rangeValue[1] = j
                                }
                            }
                        }
                    }
                }
                
            }
        }, false)
    },
}
</script>
<style>
@import url(../../static/css/base.css);
.container{
    border-radius: 8rpx;

    background: rgba(248, 210, 71, 0.1);
}
</style>